local zhasi = fk.CreateSkill {
  name = "zhasi",
  tags={Skill.Limited}
}

zhasi:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.damage >= player.hp and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#zhasi-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-zhihengs|ex__zhiheng", nil, true, false)
    room:setPlayerMark(player, "@@zhasi", 1)
    room:addPlayerMark(player, MarkEnum.PlayerRemoved, 1)
    return true
  end,
})
zhasi:addEffect(fk.TargetSpecified, {
  can_refresh = function(self, event, target, player, data)
    if target == player and player:getMark("@@zhasi") > 0 then
      return data.firstTarget and table.find(data.tos, function(p) return p~= player end)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@zhasi", 0)
    player.room:removePlayerMark(player, MarkEnum.PlayerRemoved, 1)
  end,
})
zhasi:addEffect(fk.Damaged, {
  can_refresh = function(self, event, target, player, data)
    if target == player and player:getMark("@@zhasi") > 0 then
      return true
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@zhasi", 0)
    player.room:removePlayerMark(player, MarkEnum.PlayerRemoved, 1)
  end,
})
return zhasi